package org.jeecg.modules.iot.middleware.processor.socketOperate;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.jeecg.modules.iot.model.cabinet.OpenDoorCommand;
import org.springframework.stereotype.Service;

@Service
public class CabinetControlService {

 /*   @Autowired
    private MqttSendClient mqttSendClient;*/

    private final ObjectMapper objectMapper = new ObjectMapper();

    public void sendOpenDoorCommand(String deviceSn, int door, Integer batteryType, String userId, String orderId) {
        OpenDoorCommand command = new OpenDoorCommand();
        OpenDoorCommand.Body body = new OpenDoorCommand.Body();
        body.setDoor(door);
        body.setBatteryType(batteryType);
        body.setUserId(userId);
        body.setOrderId(orderId);
        command.setBody(body);

        try {
            String payload = objectMapper.writeValueAsString(command);
            String topic = "cmd/cabinet/sd/client/" + deviceSn;
            /*mqttSendClient.publishNormal(true, topic, payload);*/
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }
}
